import { getPersonalIntro, getTeacherDetail } from '../../../../api/user'
import { checkMessageAuthority } from '../../../../api/leaveWord'

Page({
  data: {
    teacherDetail: {
      isCurrent: true
    },
    intro: {},
    activeName: 'intro',
    userId: '',
    scrollViewHeight: 0
  },
  options: {
    styleIsolation: 'shared'
  },
  onLoad: function (options) {
    this.setPageHeight();
    this.setData({ userId: options.userId });
    this.init(options.userId);
  },
  setPageHeight() {
    const _this = this
    wx.getSystemInfo({
      success: function(res) {
        _this.setData({
          scrollViewHeight: res.windowHeight
        })
      }
    });
  },
  init(userId) {
    const _this = this
    getTeacherDetail({ userId: userId }).then(res => {
      _this.setData({
        teacherDetail: res
      })
      getPersonalIntro({ userId: userId }).then(res => {
        _this.setData({
          intro: res
        })
      })
    })
  },
  onChange() {

  },
  searchTag(e) {
    const tag = e.currentTarget.dataset.tag
    wx.navigateTo({
      url: '/packageA/pages/searchResult/searchResult?keyword=' + tag.tagsName
    })
  },
  back() {
    wx.navigateBack({ delta: 1 })
  },
  toPageMessage() {
    wx.navigateTo({ url: '/packageA/pages/message/message' })
  },
  leaveWords() {
    checkMessageAuthority({
      leaveWordType: 'general',
      toUserId: this.data.userId
    }).then(res => {
      if (res) {
        wx.navigateTo({
          url: '/packageA/pages/msgRecords/msgRecords?userId=' + this.data.userId
        })
      }
    })
  }
})
